<?php
require_once('../../controller/auth.php');
//Start session
	session_start();
	
	//Include database connection details
	require_once('../../controller/inc/config.inc');
	
	
	
	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db("ttc_teachers");
	if(!$db) {
		die("Unable to select database");
	}
$field=$_POST['column'];
$pro=$_POST['pro'];
$key=$_POST['key_term'];
mysql_query ('SET NAMES utf8');
mysql_query('SET CHARACTER_SET utf8');

$sel=mysql_query("SELECT * FROM tblteachers WHERE $field like '%$key%' AND PROVINCE like '%$pro%'");


if($sel){
$count=mysql_num_rows($sel);
echo "<div class='alert alert-info'>$count Records Found!</div>";
	echo "<table class='table table-bordered'>";
	echo "<tr class='well'>";
		echo "<th>S/N</th>";
		echo "<th>Name</th>";
		echo "<th>Father Name</th>";
		echo "<th>Gender</th>";
		echo "<th>Province</th>";
		echo "<th>Education Level</th>";
		echo "<th>Education Field</th>";
		echo "<th>Academic Grade</th>";
		echo "<th>Appionted TTC Location</th>";
		
	echo "</tr>";
	//$genderArray=array(1=>'Male',2=>'Female');
	//looping through the records retrieved
	while($row = mysql_fetch_array($sel)){
		//echo "<tr class='bar$row[stu_id]'>";
		//echo "<td>{$row['first_name']}</td>";
		//echo "<td>{$row['sure_name']}</td>";
		//echo "<td>{$row['email']}</td>";
		//echo "<td>{$row['paid']}</td>";
		//echo "<td>{$row['due']}</td>";
		//echo "<td>{$row['nid']}</td>";
		
		//--------
		echo "<tr class='bar$row[id]'>";
		echo "<td>{$row['ID']}</td>";
		echo "<td>{$row['NAME']}</td>";
		echo "<td>{$row['FATHER_NAME']}</td>";
		echo "<td>{$row['GENDER']}</td>";
		echo "<td>{$row['PROVINCE']}</td>";
		
		
		echo "<td>{$row['EDUCATION_LEVEL']}</td>";
		echo "<td>{$row['EDUCATION_FIELD']}</td>";
		echo "<td>{$row['ACADEMIC_GRADE']}</td>";
		echo "<td>{$row['APPOINTED_TTC_LOCATION']}</td>";
		//-------
		
		echo "</tr>";
	}  
	echo "</table>";
}
else{
 echo "<div class='alert alert-error'>No Record Found! | You have not selected a category | Keyword is Empty</div>";	
}

	



?>